﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;//添加命令空间，可以使用OleDbConnection等对象
using System.Data;//添加命令空间，可以使用dataset

public partial class adminstrator_changeteacher : System.Web.UI.Page
{
    public string tNo { get; set; }public OleDbConnection myConnection;
    public static readonly string sConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQLConnStriing"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sConnectionString);
        myConnection.Open();//打开数据库连接
        if (Session["UserName"] == null && Session["UserNo"] == null)//没有经过正常连接途径打开页面
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登陆！');parent.location.herf='../login.aspx'</script>", false);
        tNo = Request.QueryString["tNo"];
        if (!IsPostBack)//首次打开页面
            bind(tNo);//首次打开页面,默认选择“男”
    }

    protected void ButtonOK_Click(object sender, EventArgs e)
    {
        string tName = TeacherName.Text.Trim();//获取输入的姓名
        string tSex;
        if (RadioButtonMan.Checked == true)
            tSex = "男";
        else
            tSex = "女";
        string tDepartment = DropDownListDepartment.SelectedItem.Text.Trim();//获取输入的部门
        string tPass = TeacherPass.Text.Trim();//获取输入的密码
        string mystr = "update TeacherTb set tName='" + tName + "' .tDepartment='" + tDepartment + "'.tPass='" + tPass + "where tNo='" + tNo;
        OleDbCommand mycmd = new OleDbCommand(mystr, myConnection);
        mycmd.ExecuteNonQuery();//修改teachertb表中的教师姓名
        mystr = "Update ScoreTb set tName ='" + tName + "'where tNo='" + tNo + "'";//更新成绩表
        mycmd = new OleDbCommand(mystr, myConnection);
        mycmd.ExecuteNonQuery();//修改scoretb表中的教师姓名
        mystr = "Update ScoreTb set tName ='" + tName + "'where tNo='" + tNo + "'";//更新课程表
        mycmd = new OleDbCommand(mystr, myConnection);
        mycmd.ExecuteNonQuery();//修改coursetb表中的教师姓名
        mystr = "Update ScoreTb set tName ='" + tName + "'where tNo='" + tNo + "'";//更新选课表
        mycmd = new OleDbCommand(mystr, myConnection);
        mycmd.ExecuteNonQuery();//修改coursetb表中的教师姓名
        mystr = "Update ScoreTb set tName ='" + tName + "'where tNo='" + tNo + "'";//更新课程表
        mycmd = new OleDbCommand(mystr, myConnection);
        mycmd.ExecuteNonQuery();//执行SQL语句
        //修改ManageTb表中的教师姓名
        mystr = "Update ManageTb set tName ='" + tName + "'where tNo='" + tNo + "'";//更新管理员表
        mycmd = new OleDbCommand(mystr, myConnection);
        mycmd.ExecuteNonQuery();//执行SQL语句
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
               "alert('教师信息修改成功！');</script>", false);
    }
    protected void ButtonReset_Click(object sender, EventArgs e)/*点击“重置”按钮*/
    {
        bind(tNo);
    }
    public void bind(string myNo)/*向文本框和列表框绑定数据的函数*/
    {
        string mysql = "select * from TeacherTb where tNo ='" + myNo + "'";
        OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);// OleDbCommand表示要对access数据源执行的sql语句或存储过程
        OleDbDataReader myReader = mycmd.ExecuteReader();//执行SQL语句，存储在myReader
        if (myReader.Read())
        {
            //***取出教师的各项信息        }
        }
    }
}